<?php

/**
 * This is the model class for table "account_data".
 *
 * The followings are the available columns in table 'account_data':
 * @property integer $id
 * @property string $name
 * @property string $password
 * @property integer $activated
 * @property integer $access_level
 * @property integer $membership
 * @property integer $last_server
 * @property string $last_ip
 * @property string $ip_force
 * @property string $expire
 * @property string $credits
 * @property string $email
 * @property string $last_logout
 * @property string $last_mac
 */
class AccountData extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AccountData the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return CDbConnection database connection
	 */
	public function getDbConnection()
	{
		return Yii::app()->ls_db;
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'account_data';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, password', 'required'),
			array('activated, access_level, membership, last_server', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>45),
			array('password', 'length', 'max'=>65),
			array('last_ip, ip_force, last_mac', 'length', 'max'=>20),
			array('credits, last_logout', 'length', 'max'=>21),
			array('email', 'length', 'max'=>30),
			array('expire', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, password, activated, access_level, membership, last_server, last_ip, ip_force, expire, credits, email, last_logout, last_mac', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'password' => 'Password',
			'activated' => 'Activated',
			'access_level' => 'Access Level',
			'membership' => 'Membership',
			'last_server' => 'Last Server',
			'last_ip' => 'Last Ip',
			'ip_force' => 'Ip Force',
			'expire' => 'Expire',
			'credits' => 'Credits',
			'email' => 'Email',
			'last_logout' => 'Last Logout',
			'last_mac' => 'Last Mac',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('activated',$this->activated);
		$criteria->compare('access_level',$this->access_level);
		$criteria->compare('membership',$this->membership);
		$criteria->compare('last_server',$this->last_server);
		$criteria->compare('last_ip',$this->last_ip,true);
		$criteria->compare('ip_force',$this->ip_force,true);
		$criteria->compare('expire',$this->expire,true);
		$criteria->compare('credits',$this->credits,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('last_logout',$this->last_logout,true);
		$criteria->compare('last_mac',$this->last_mac,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}